﻿using System;
using System.IO;
using System.Net;
using System.Text;

namespace Kkbac.Tools
{
    public class GetHtml
    {
        public bool IsSuccess;

        public GetHtml()
        {
            IsSuccess = false;
        }

        public string Get(string url)
        {
            Encoding encoding = Encoding.Default;
            var html = Get(url, encoding);
            return html;
        }

        public string Get(string url, Encoding encoding)
        {
            var html = "";
            try
            {
                WebRequest request = WebRequest.Create(url);
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(),
                    encoding);

                html = reader.ReadToEnd();

                reader.Close();
                reader.Dispose();
                response.Close();

                IsSuccess = true;
            }
            catch (Exception ex)
            {
                IsSuccess = false;
                html = ex.Message;
            }
            return html;
        }

    }

}
